package com.syyo.gulimall.member.controller;

//import org.springframework.security.access.prepost.PreAuthorize;

import com.syyo.common.domain.ResultVo;
import com.syyo.common.utils.ResultUtils;
import com.syyo.common.vo.MemberVo;
import com.syyo.gulimall.member.domain.req.MemberReq;
import com.syyo.gulimall.member.domain.vo.MemberLoginVo;
import com.syyo.gulimall.member.domain.vo.MemberRegistVo;
import com.syyo.gulimall.member.domain.vo.SocialUser;
import com.syyo.gulimall.member.service.MemberService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;


/**
 * 会员
 *
 * @author syyo
 * @email syyo@gmail.com
 * @date 2021-01-20 09:52:10
 */
@RestController
@RequestMapping("/member/member")
public class MemberController {

    @Autowired
    private MemberService memberService;


    /**
     * 新增
     */
    @PostMapping
    // @PreAuthorize("@syyo.check('system:member:add')")
    public ResultVo add(@RequestBody MemberReq req) {
        return ResultUtils.ok(memberService.add(req));
    }

    /**
     * 删除
     */
    @DeleteMapping("/{id}")
    // @PreAuthorize("@syyo.check('system:member:del')")
    public ResultVo del(@PathVariable("id") Integer id) {
        return ResultUtils.ok(memberService.del(id));
    }

    /**
     * 修改
     */
    @PutMapping
    // @PreAuthorize("@syyo.check('system:member:edit')")
    public ResultVo edit(@RequestBody MemberReq req) {
        return ResultUtils.ok(memberService.edit(req));
    }

    /**
     * 信息
     */
    @GetMapping("/{id}")
    public ResultVo findOne(@PathVariable("id") Integer id) {
        return ResultUtils.ok(memberService.findOne(id));
    }

    /**
     * 列表
     */
    @GetMapping("/list/{pageNum}/{pageSize}")
    public ResultVo findPage(@PathVariable("pageNum") Integer pageNum,
                             @PathVariable("pageSize") Integer pageSize,
                             MemberReq req) {
        return ResultUtils.ok(memberService.findPage(pageNum, pageSize, req));
    }

    /**
     * 列表
     */
    @GetMapping("/list")
    public ResultVo findAll(MemberReq req) {
        return ResultUtils.ok(memberService.findAll(req));
    }

    /**
     * 注册会员功能
     */
    @PostMapping("/regist")
    // @PreAuthorize("@syyo.check('system:member:add')")
    public ResultVo regist(@RequestBody MemberRegistVo req) {
        return ResultUtils.ok(memberService.regist(req));
    }

    /**
     * 登录功能
     */
    @PostMapping("/login")
    // @PreAuthorize("@syyo.check('system:member:add')")
    public ResultVo login(@RequestBody MemberLoginVo req) {
        return ResultUtils.ok(memberService.login(req));
    }

    /**
     * 社交账号登录
     */
    @PostMapping("auth/login")
    // @PreAuthorize("@syyo.check('system:member:add')")
    public MemberVo authlogin(@RequestBody SocialUser req) {
        return memberService.authlogin(req);
    }
}
